package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.domain.SysCourse;
import com.ruoyi.system.mapper.SysCourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysSingleQuestionMapper;
import com.ruoyi.system.domain.SysSingleQuestion;
import com.ruoyi.system.service.ISysSingleQuestionService;
import com.ruoyi.common.core.text.Convert;

/**
 * 单选题Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-24
 */
@Service
public class SysSingleQuestionServiceImpl implements ISysSingleQuestionService 
{
    @Autowired
    private SysSingleQuestionMapper sysSingleQuestionMapper;

    @Autowired
    private SysCourseMapper sysCourseMapper;

    /**
     * 查询单选题
     * 
     * @param id 单选题主键
     * @return 单选题
     */
    @Override
    public SysSingleQuestion selectSysSingleQuestionById(Long id)
    {
        return sysSingleQuestionMapper.selectSysSingleQuestionById(id);
    }

    /**
     * 查询单选题列表
     * 
     * @param sysSingleQuestion 单选题
     * @return 单选题
     */
    @Override
    public List<SysSingleQuestion> selectSysSingleQuestionList(SysSingleQuestion sysSingleQuestion)
    {
        return sysSingleQuestionMapper.selectSysSingleQuestionList(sysSingleQuestion);
    }

    /**
     * 新增单选题
     * 
     * @param sysSingleQuestion 单选题
     * @return 结果
     */
    @Override
    public int insertSysSingleQuestion(SysSingleQuestion sysSingleQuestion)
    {
        // 查询课程信息
        SysCourse sysCourse = sysCourseMapper.selectSysCourseById(sysSingleQuestion.getCourseId());
        sysSingleQuestion.setCourseName(sysCourse.getCourseName());
        sysSingleQuestion.setCreateBy(ShiroUtils.getLoginName());
        sysSingleQuestion.setCreateTime(DateUtils.getNowDate());
        return sysSingleQuestionMapper.insertSysSingleQuestion(sysSingleQuestion);
    }

    /**
     * 修改单选题
     * 
     * @param sysSingleQuestion 单选题
     * @return 结果
     */
    @Override
    public int updateSysSingleQuestion(SysSingleQuestion sysSingleQuestion)
    {
        sysSingleQuestion.setUpdateTime(DateUtils.getNowDate());
        return sysSingleQuestionMapper.updateSysSingleQuestion(sysSingleQuestion);
    }

    /**
     * 批量删除单选题
     * 
     * @param ids 需要删除的单选题主键
     * @return 结果
     */
    @Override
    public int deleteSysSingleQuestionByIds(String ids)
    {
        return sysSingleQuestionMapper.deleteSysSingleQuestionByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除单选题信息
     * 
     * @param id 单选题主键
     * @return 结果
     */
    @Override
    public int deleteSysSingleQuestionById(Long id)
    {
        return sysSingleQuestionMapper.deleteSysSingleQuestionById(id);
    }
}
